<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="box">
        <ul>
           
        </ul>
    </div>
    <button>加载图片</button>
    <script src="./jquery-3.7.1.js"></script>
    <script>
        $(function(){

            $("button").click(function(){
                $("ul").load("2.json",function(d){
                    var obj = JSON.parse(d);
                    
                    // for (let index = 0; index < obj.length; index++) {
                    //     const element = obj[index];
                    //     console.log(element.img);
                    // }

                    // console.log("--------------------");

                    obj.forEach(element => {
                        // 模板字符串实现 节点定义
                        var str = `<li><img src="${element.img}" alt=""></li>`;

                        $("ul").append($(str))
                        
                    });

                })
            });
           
        })
    </script>
</body>
</html>